package com.jlect.swebing.ui.client;

import com.jlect.swebing.ui.client.laf.LabelUI;
import com.jlect.swebing.ui.client.laf.UIManager;
import com.jlect.swebing.util.client.Strings;

/**
 * Label component implementation
 *
 * @author Sergey Kozmin
 * @since 17.11.2007 20:05:31
 */
public class GLabel extends GComponent {
    private static final String uiComponentID = "GLabel";

    public static final String LABEL_TEXT_PROPERTY_NAME = "label.text";

    private String text;

    public GLabel(String text) {
        updateUI();
        setText(text);
        setPreferredSize(getUI().getPreferredSize());//todo use font metrix
    }

    public GLabel() {
        this("");
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        if(!Strings.isEqual(this.text, text)) {
            firePropertyChanged(LABEL_TEXT_PROPERTY_NAME, this.text, text);
            this.text = text;
        }
    }

    public LabelUI getLabelUI() {
        return (LabelUI) getUI();
    }

    public void updateUI() {
        setUI(UIManager.getInstance().getUI(this));
    }
    
    public String getUiComponentID() {
        return uiComponentID;
    }
}
